package main

import (
	"bufio"
	"fmt"
	"os"

	"./pipelineMiddleWare"
)

func mainYYY() {
	// out := pipelineMiddleWare.ArraySource(2, 3, 40, 5, 21, 32, 89, 7, 48, 6)
	//  time.Sleep(2 * time.Second)
	//fmt.Println(out)

	// out = pipelineMiddleWare.InMemorySort(out)

	// out = pipelineMiddleWare.Merge(pipelineMiddleWare.InMemorySort(out), pipelineMiddleWare.InMemorySort(pipelineMiddleWare.ArraySource(36, 3, 34, 5, 25, 32, 9, 7, 14, 6)))

	out := pipelineMiddleWare.MergeN(pipelineMiddleWare.InMemorySort(pipelineMiddleWare.ArraySource(2, 3, 40, 5, 21, 32, 89, 7, 48, 6)),
		pipelineMiddleWare.InMemorySort(pipelineMiddleWare.ArraySource(36, 3, 34, 5, 25, 32, 9, 7, 14, 6)),
		pipelineMiddleWare.InMemorySort(pipelineMiddleWare.ArraySource(31, 31, 54, 58, 56, 7, 10, 3, 5, 9)))

	for v := range out {
		fmt.Println(v)
	}

	pipelineMiddleWare.UseTime()
}

func main() {
	var fileName = "data1.in"

	count := 1000
	file, err := os.Create(fileName)
	if err != nil {
		panic(err)
	}

	defer file.Close()

	mypipe := pipelineMiddleWare.RandomSource(count)
	writer := bufio.NewWriter(file)

	pipelineMiddleWare.WriterSlink(writer, mypipe)
	writer.Flush()

	//for v := range mypipe {
	//	fmt.Println(v)
	//}

	file, err = os.Open(fileName)
	if err != nil {
		panic(err)
	}
	defer file.Close() //延迟关闭文件
	mypipeX := pipelineMiddleWare.ReaderSource(file, -1)

	mypipeX = pipelineMiddleWare.InMemorySort(mypipeX)

	readSize := 0

	for v := range mypipeX {

		fmt.Println(v)

		readSize++
	}

	fmt.Println(readSize)

	pipelineMiddleWare.UseTime()

}
